package com.yxq.mdt.app.modules.personal.model;

import com.yxq.mdt.app.base.ibase.IBaseModel;
import com.yxq.mdt.app.modules.personal.bean.CollectTopicListBean;
import com.yxq.mdt.app.modules.personal.bean.PublishBean;
import com.yxq.mdt.app.modules.personal.bean.TopicCommentBean;
import com.yxq.mdt.app.net.ApiModel;
import com.yxq.mdt.app.net.BaseObserver;
import com.yxq.mdt.app.net.RetrofitFactory;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * @author L
 * @time 2019-11-25
 * @describe 我的-发表$
 */
public class PublishModel implements IBaseModel {

    public void selectTopicInfoList(int pageNum, int pageSize, ApiModel.CommonCallback<PublishBean> callback) {
        RetrofitFactory.getJavaRetrofit().create(PublishAPI.class)
                .selectTopicInfoList(pageNum, pageSize)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<PublishBean>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(PublishBean respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    public void selectMyTopicFavour(int pageNum, int pageSize, ApiModel.CommonCallback<CollectTopicListBean> callback) {
        RetrofitFactory.getJavaRetrofit().create(PublishAPI.class)
                .selectMyTopicFavour(pageNum, pageSize)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<CollectTopicListBean>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(CollectTopicListBean respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    public void selectMyTopicComment(int pageNum, int pageSize, ApiModel.CommonCallback<TopicCommentBean> callback) {
        RetrofitFactory.getJavaRetrofit().create(PublishAPI.class)
                .selectMyTopicComment(pageNum, pageSize)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<TopicCommentBean>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(TopicCommentBean respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    public static void delGsTopicComment(String id, ApiModel.CommonCallback<String> callback) {
        RetrofitFactory.getJavaRetrofit().create(PublishAPI.class)
                .delGsTopicComment(id)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<String>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(String respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    public static void delPublish(String id, ApiModel.CommonCallback<String> callback) {
        RetrofitFactory.getJavaRetrofit().create(PublishAPI.class)
                .delPublish(id)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<String>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(String respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    @Override
    public void onDestroy() {

    }
}
